package com.ly.quickdev.library.fragment;

import com.ly.quickdev.library.app.BaseAppContext;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class ImageFragment extends DevBaseFragment {

	private ImageView mImageView;

	private String mUrl;

	private static final String URL = "url";

	public static ImageFragment getInstance(String url) {
		ImageFragment fragment = new ImageFragment();
		Bundle b = new Bundle();
		b.putString(URL, url);
		fragment.setArguments(b);
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mUrl = getArguments().getString(URL);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		mImageView = new ImageView(getActivity());
		mImageView.setScaleType(ScaleType.CENTER_CROP);
		return mImageView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		BaseAppContext.displayImage(mImageView, mUrl);
	}
}
